$(document).ready(function(){	
	//console.log(find_chk);	
	$(document).on("keydown.NewActionOnF5", function(e){
		var charCode = e.which || e.keyCode;
		switch(charCode){
			case 116: // F5
				e.preventDefault();
				window.location = "index.php";
				break;
		}
	});
	
	$('.inputNumber').keydown(function(event) {
		// Allow special chars + arrows 
		if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 
			|| event.keyCode == 27 || event.keyCode == 13 
			|| (event.keyCode == 65 && event.ctrlKey === true) 
			|| (event.keyCode >= 35 && event.keyCode <= 39)){
				return;
		}else {
			// If it's not a number stop the keypress
			if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
				event.preventDefault(); 
			}   
		}
	});
});	


function reloadPage(){
	window.location = 'index.php';
}	

var delayAlert=null; 
function alertPopup(alertid){
	$('#'+alertid+'').fadeIn(500, function() {
		clearTimeout(delayAlert);  
		delayAlert=setTimeout(function(){  
			$('#'+alertid+'').fadeOut(1000); 			
			reloadPage();  		
			delayAlert=null;  
		},2000);  
	});
}


function checkEmail(email) {
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(email))) {
		//console.log('กรุณากรอก email ให้ถูกต้อง');
		return 0; 
	} else {
		return 1; 
	}
}

var myApp;
myApp = myApp || (function () {
    var pleaseWaitDiv = $('<div class="modal hide" id="pleaseWaitDialog" data-backdrop="static" data-keyboard="false"><div class="modal-header"><h1>Processing...</h1></div><div class="modal-body"><div class="progress progress-striped active"><div class="bar" style="width: 100%;"></div></div></div></div>');
    return {
        showPleaseWait: function() {
            pleaseWaitDiv.modal();
        },
        hidePleaseWait: function () {
            pleaseWaitDiv.modal('hide');
        },

    };
})();


function fnLock(id){
	myApp.showPleaseWait();	
	jQuery.ajax( {
		url :'modules/mod_dealer/fn_lock.php',
		type: 'GET',
		data: 'id='+id+'',
		dataType: 'jsonp',
		dataCharset: 'jsonp',
		success: function (data){
			console.log(data.show);
			$('#showstatus'+id+'').html(data.show);	
			$('#lockstatus'+id+'').html(data.icon);	
			myApp.hidePleaseWait();
			 //pleaseWaitDiv.modal('hide');
			/*clearTimeout(delayAlert);  
            delayAlert=setTimeout(function(){          
                reloadPage();                 
                delayAlert=null;  
            },2000);  */
		}
	});
}